// Su dung co tro ham
#include <iostream>
using namespace std;
void SapXep ( int mang[], int n, void (*SoSanh) ( int &, int &) );
void TangDan ( int &a, int &b);
void GiamDan ( int &a, int &b);
void Swap ( int &a, int &b);
void In ( int mang[], int n);
int main(){
	int *mang;
	int n;
	cout << "So phan tu:";
	cin >> n;
	mang = new int [n];
	for ( int i = 0; i < n; i++){
		cout << "[" << i << "] = ";
		cin >> mang[i];
	}
	cout << "Tang dan:";
	SapXep ( mang, n, &TangDan);
	In ( mang, n);
	cout << endl;
	cout << "Giam dan";
	SapXep ( mang, n, &GiamDan);
	In ( mang, n);
	cout << endl;
	system ("pause");
	return 0;
}
void TangDan ( int &a, int &b){
	if ( a > b) Swap ( a, b);
}
void GiamDan ( int &a, int &b){
	if ( a < b) Swap ( a, b);
}
void Swap ( int &a, int &b){
	int c;
	c = a;
	a = b;
	b = c;
}
void In ( int mang[], int n){
	for ( int i = 0; i < n; i++) cout << mang [i] << ", ";
}
void SapXep ( int mang[], int n, void (*SoSanh) ( int &, int &)){
	for ( int i = 0; i < n - 1; i++){
		for ( int t = 0; t < n - 1; t++){
			SoSanh ( mang[t], mang[t+1]);
		}
	}
}